package com.wnhz.work.jy.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.nostra13.universalimageloader.core.ImageLoader;
import com.wnhz.work.jy.R;
import com.wnhz.work.jy.bean.ScoreBean;

import java.util.List;

/**
 * Created by Administrator on 2016/10/10 0010.
 */
public class ScoreAdapter extends BaseAdapter {
    private Context context;
    private List<ScoreBean> scoreList;
    private View.OnClickListener listener;

    public ScoreAdapter(Context context, List<ScoreBean> scoreList, View.OnClickListener listener) {
        this.context = context;
        this.scoreList = scoreList;
        this.listener = listener;
    }

    @Override
    public int getCount() {
        return scoreList.size();
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ScoreViewHolder viewHolder = new ScoreViewHolder();
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.score_item, null);
            viewHolder.imag = (ImageView) convertView.findViewById(R.id.iv_pic);
            viewHolder.title = (TextView) convertView.findViewById(R.id.tv_title);
            viewHolder.number = (TextView) convertView.findViewById(R.id.tv_num);
            viewHolder.tv_bean_num = (TextView) convertView.findViewById(R.id.tv_bean_num);

            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ScoreViewHolder) convertView.getTag();
        }

        if (scoreList.get(position).getImage() != null && !"".equals(scoreList.get(position).getImage()) && !"null".equals(scoreList.get(position).getImage())) {
            ImageLoader.getInstance().displayImage(scoreList.get(position).getImage(), viewHolder.imag);
        } else {

        }

        if (scoreList.get(position).getTitle() != null && !"".equals(scoreList.get(position).getTitle()) && !"null".equals(scoreList.get(position).getTitle())) {
            viewHolder.title.setText(scoreList.get(position).getTitle());
        } else {
            viewHolder.title.setText("null");
        }

        if (scoreList.get(position).getNumber() != null && !"".equals(scoreList.get(position).getNumber()) && !"null".equals(scoreList.get(position).getNumber())) {
            viewHolder.number.setText("可兑换量：" + scoreList.get(position).getNumber());
        } else {
            viewHolder.number.setText("null");
        }

        if (scoreList.get(position).getBeans() != null && !"".equals(scoreList.get(position).getBeans()) && !"null".equals(scoreList.get(position).getBeans())) {
            viewHolder.tv_bean_num.setText(scoreList.get(position).getBeans());
        } else {
            viewHolder.tv_bean_num.setText("null");
        }


        return convertView;
    }

    class ScoreViewHolder {
        ImageView imag;
        TextView title;
        TextView number;
        TextView tv_bean_num;
    }
}
